package com.mars.foodserver.controller.admin;

import com.mars.foodserver.request.FoodRequest;
import com.mars.foodserver.response.result.R;
import com.mars.foodserver.service.IFoodService;
import org.springframework.web.bind.annotation.*;
import lombok.AllArgsConstructor;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-07-19
 */
@RestController
@RequestMapping("admin/food")
@AllArgsConstructor
public class AdminFoodController {

    final IFoodService foodService;

    /**
     * 添加
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/add")
    public R add(@RequestBody FoodRequest request) {
        foodService.add(request);
        return R.success();
    }

    /**
     * 更新
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/update")
    public R update(@RequestBody FoodRequest request) {
        foodService.update(request);
        return R.success();
    }

    /**
     * 更新审核状态
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/updateStatusDown")
    public R updateStatusDown(@RequestBody FoodRequest request) {
        foodService.updateStatusDown(request.getId());
        return R.success();
    }

    @PostMapping("/updateStatus")
    public R updateStatus(@RequestBody FoodRequest request) {
        foodService.updateStatus(request.getId(), request.getIsRecommend());
        return R.success();
    }


    /**
     * 删除
     *
     * @param id ID
     * @return R
     */
    @GetMapping("/delete")
    public R delete(Integer id) {
        foodService.delete(id);
        return R.success();
    }

    /**
     * 详情
     *
     * @param id ID
     * @return R
     */
    @GetMapping("/detail")
    private R detail(Integer id) {
        return R.success(foodService.detail(id));
    }


    /**
     * 分页
     *
     * @param request 请求参数
     * @return R
     */
    @PostMapping("/page")
    private R page(@RequestBody FoodRequest request) {
        return R.success(foodService.page(request));
    }
}
